package com.zlzxm.sorting.util.net;


import com.google.gson.Gson;

import retrofit2.HttpException;
import retrofit2.Response;

/**
 * CREATE BY zlzxm ON 2022/8/3
 */
public class NetExceptionHelp {


    public static String convertError(Exception e){

        if(e instanceof HttpException){


            return convertError(((HttpException) e).response());

        }else {

            return "app错误:"+e.getMessage();
        }


    }

    public static String convertError(Response response){

        try {

            String body =  response.errorBody().string();

            String error = new Gson().fromJson(body, ErrorBody.class).getMessage();


            return "错误代码:"+ response.code()+"  "+error;


        } catch (Exception e) {
            return "错误代码:"+ response.code()+"";
        }


    }

}
